# -*- coding: utf-8 -*-
"""
______________________________
  Author: 安智军
  Email :  1010666711@qq.com
   Time : 2023/8/6 16:03
    File: base_page.py
Software: PyCharm
______________________________
"""
from selenium import webdriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

class BaesPage:

    def __init__(self, base_driver=None):
        if base_driver:
            self.driver = base_driver
        else:
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(10)
            self.driver.maximize_window()

    def do_find(self, by):
        """
        获取单个元素
        :param by:
        :return:
        """
        print("do_find元组为:", by)
        return self.driver.find_element(*by)

    def do_finds(self, by):
        """
        获取多个元素
        :param by:
        :return:
        """
        return self.driver.find_elements(*by)  # *by 元组解包

    def do_send_keys(self, value, by):
        """
        获取多个元素
        :param by:
        :return:
        """
        # ele = self.do_find(*by)
        ele = self.do_find(by)
        ele.clear()
        ele.send_keys(value)

    def do_click(self, by):
        """
        做点击操作  操作抽离
        :return:
        """
        return self.do_find(by).click()

    def do_quit(self):
        self.driver.quit()

    def wait_visible(self, locator: tuple):
        """等待可见"""
        return WebDriverWait(self.driver, 10) \
            .until(expected_conditions.visibility_of_element_located(locator))
